package com.cug.smartranch.animal.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cug.smartranch.animal.admin.dto.req.EquipmentSaveReqDTO;
import com.cug.smartranch.animal.admin.dto.req.FeedEquipmentPageQueryReqDTO;
import com.cug.smartranch.animal.admin.dto.resp.FeedEquipmentPageQueryRespDTO;
import com.cug.smartranch.animal.admin.service.FeedEquipmentService;
import com.cug.smartranch.framework.result.Result;
import com.cug.smartranch.framework.web.Results;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 喂养设备记录控制层
 */
@RestController
@RequiredArgsConstructor
@Tag(name = "喂养设备管理")
@RequestMapping("/api/feed_admin/feedEquipment")
public class FeedEquipmentController {

    private final FeedEquipmentService feedEquipmentService;

    @Operation(summary = "用户创建喂养设备记录")
    @PostMapping("/create")
    public Result<Void> createAnimal(@RequestBody EquipmentSaveReqDTO requestParam) {
        feedEquipmentService.createEquipment(requestParam);
        return Results.success();
    }

    @Operation(summary = "用户分页查询所有喂养设备信息")
    @GetMapping("/select/all")
    public Result<IPage<FeedEquipmentPageQueryRespDTO>> selectAllFeedEquipment(FeedEquipmentPageQueryReqDTO requestParam) {
        IPage<FeedEquipmentPageQueryRespDTO> list = feedEquipmentService.selectAllFeedEquipment(requestParam);
        return Results.success(list);
    }

    @Operation(summary = "用户启动或关闭设备")
    @PostMapping("/enableOrClose")
    public Result<Void> enableOrClose(@RequestParam Integer status,@RequestParam Long id) {
        feedEquipmentService.enableOrClose(status,id);
        return Results.success();
    }
}
